package com.hbue.springboot.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbue.springboot.pojo.TbCustomer;
import com.hbue.springboot.service.ManageCustomerService;
import com.hbue.springboot.utils.QueryParams;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/TbCustomer")
@RequiredArgsConstructor
public class ManageCustomerController {
    private final ManageCustomerService manageCustomerService;

    @GetMapping("/getAllCustomers")
    public List<TbCustomer> getAllCustomer() {
        return manageCustomerService.getAllCustomers();
    }

    @PostMapping("/addCustomer")
    public int addCustomer(@RequestBody TbCustomer tbCustomer) {
        return manageCustomerService.addCustomer(tbCustomer);
    }

    @DeleteMapping("/deleteCustomer/{id}")
    public int deleteCustomer(@PathVariable int id) {
        return manageCustomerService.deleteCustomer(id);
    }

    @PutMapping("/updateCustomer")
    public int updateCustomer(@RequestBody TbCustomer tbCustomer) {
        System.out.println(tbCustomer.getId() + tbCustomer.getCustName());
        return manageCustomerService.updateCustomer(tbCustomer);
    }

    @GetMapping("getCustomerByName")
    public List<TbCustomer> getCustomerByName(@RequestParam String name) {
        return manageCustomerService.getCustomerByName(name);
    }

    @PostMapping("listCustomersByPage")
    public IPage<TbCustomer> listCustomersByPage(@RequestBody QueryParams queryParams) {
        return manageCustomerService.listCustomer(queryParams);
    }
}
